package org.akushe.core.security;

import javax.jcr.Credentials;
import javax.jcr.SimpleCredentials;

import org.akushe.core.config.Configuration;
import org.akushe.core.constant.CommonConstant;

public class CredentialFactory {

	private static Configuration config;
	
	public static Credentials createCredential(String name){
		
		loadConfiguration();
		
		if(name == null){
			throw new RuntimeException("No credential type provided");
		}
		else if(name.equals(CommonConstant.SIMPLE_CREDENTIAL)){
			return new SimpleCredentials(config.getJcrLogin(), config.getJcrPassword().toString().toCharArray());
		}
		else{
			throw new RuntimeException("Invalid credential type provided");
		}
		
	}
	private static void loadConfiguration(){
		config = Configuration.getInstance();
		
	}
}
